function $(id){
    return document.getElementById(id);
}

window.onload = function (){
    cutByItem(1);
}

/**
 * 动态条件分页查询
 * @param pageNO 页码
 */
function cutByItem(pageNO){
    axios.get("/em/cutByItem",{
        params:{
            pageNO,
            name : $("nameTxt").value,
            startDate : $("startDateTxt").value,
            endDate : $("endDateTxt").value
        }
    }).then(resp =>{
        var info = resp.data;
        var str = "";
        info.records.forEach(n =>{
           str += `<tr><td>${n.name}</td><td>${n.birthday}</td>
                   <td>${n.money}</td>
                   <td><input type="button" value="删除" onclick="del(${n.id})">
                   <input type="button" value="修改" 
                   onclick="location.href='/employee/update.html?id=${n.id}'"></td></tr>`;
        });
        $("data").innerHTML = str;

        var cutStr = "";
        for(var i=1;i<=info.pages;i++){
            cutStr += `<a style="margin-left: 10px"
                    href="javascript:cutByItem(${i})">${i}</a>`;
        }
        $("cutDiv").innerHTML = cutStr;
    });
}

function del(id){
    axios.get("/em/del",{
        params: {
            id
        }
    }).then(resp =>{
        if(resp.data == "ok"){
            cutByItem(1);
        }
    });
}